package com.stella.ieproductivitybackend.controller;

import com.stella.ieproductivitybackend.entity.*;
import com.stella.ieproductivitybackend.service.ModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 型体页控制层
 */
@RestController
@RequestMapping("/model")
public class ModelController {
    @Autowired
    private ModelService modelService;

    /**
     * 工厂列表
     */
    @PostMapping("/getFactoryList")
    public List<Factory> getFactoryList(@RequestBody Map<String, Object> param) {
        String model = param.get("model") != null ? param.get("model").toString() : "";
        return modelService.getFactoryList(model);
    }

    /**
     * 品牌列表
     */
    @PostMapping("/getBrandList")
    public List<Brand> getBrandList(@RequestBody Map<String, Object> param) {
        String model = param.get("model") != null ? param.get("model").toString() : "";
        return modelService.getBrandList(model);
    }

    /**
     * 型体列表
     */
    @PostMapping("/getModelList")
    public List<Model> getModelList() {
        return modelService.getModelList();
    }

    /**
     * 搜索型体
     */
    @PostMapping("/searchModel")
    public List<Model> searchModel(@RequestBody Map<String, Object> params) {
        String model = params.get("model") != null ? params.get("model").toString() : "";
        return modelService.searchModel(model);
    }

    /**
     * 纯粹达成率选项
     */
    @PostMapping("/getPureOption")
    public Map<String, Object> getPureOption(@RequestBody Map<String, Object> params) {
        String model = params.get("model") != null ? params.get("model").toString() : "";
        return modelService.getPureOption(model);
    }

    /**
     * 纯粹达成率详情
     */
    @PostMapping("/getPureDetail")
    public List<ModelPure> getPureDetail(@RequestBody Map<String, Object> params) {
        String model = params.get("model") != null ? params.get("model").toString() : "";
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String year = params.get("year") != null ? params.get("year").toString() : "";
        String month = params.get("month") != null ? params.get("month").toString() : "";
        return modelService.getPureDetail(model, factory, year, month);
    }

    /**
     * 纯粹达成率图表
     */
    @PostMapping("/getPureChart")
    public Map<String, Object> getPureChart(@RequestBody Map<String, Object> params) {
        String model = params.get("model") != null ? params.get("model").toString() : "";
        return modelService.getPureChart(model);
    }

    /**
     * 入库标准秒值图表
     */
    @PostMapping("/getWarehousingChart")
    public Map<String, Object> getWarehousingChart(@RequestBody Map<String, Object> params) {
        String model = params.get("model") != null ? params.get("model").toString() : "";
        return modelService.getWarehousingChart(model);
    }

    /**
     * 入库标准秒值详情
     */
    @PostMapping("/getWarehousingDetail")
    public List<Warehousing> getWarehousingDetail(@RequestBody Map<String, Object> params) {
        String model = params.get("model") != null ? params.get("model").toString() : "";
        String year = params.get("year") != null ? params.get("year").toString() : "";
        String month = params.get("month") != null ? params.get("month").toString() : "";
        return modelService.getWarehousingDetail(model, year, month);
    }

    /**
     * 标准秒值选项
     */
    @PostMapping("/getStandardOption")
    public Map<String, Object> getStandardOption(@RequestBody Map<String, String> params) {
        String model = params.get("model") != null ? params.get("model") : "";
        return modelService.getStandardOption(model);
    }

    /**
     * 标准秒值详情
     */
    @PostMapping("/getStandardDetail")
    public List<Standard> getStandardDetail(@RequestBody Map<String, String> params) {
        String model = params.get("model") != null ? params.get("model") : "";
        String factory = params.get("factory") != null ? params.get("factory") : "";
        String revision = params.get("revision") != null ? params.get("revision") : "";
        String dmaterial = params.get("dmaterial") != null ? params.get("dmaterial") : "";
        return modelService.getStandardDetail(model, factory, revision, dmaterial);
    }

    /**
     * 直工 PPH 选项
     */
    @PostMapping("/getDirectOption")
    public Map<String, Object> getDirectOption(@RequestBody Map<String, Object> params) {
        String model = params.get("model") != null ? params.get("model").toString() : "";
        return modelService.getDirectOption(model);
    }

    /**
     * 直工PPH
     */
    @PostMapping("/getDirectPPH")
    public List<DirectPPH> getDirectPPH(@RequestBody Map<String, Object> params) {
        String model = params.get("model") != null ? params.get("model").toString() : "";
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String year = params.get("year") != null ? params.get("year").toString() : "";
        String month = params.get("month") != null ? params.get("month").toString() : "";
        return modelService.getDirectPPH(model, factory, year, month);
    }
}
